﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Win32;
using System.IO;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Collections;
using System.Drawing;

public partial class information : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DBaccess db = new DBaccess();
        String getRid = HttpContext.Current.Request.QueryString["rid"];
        DataSet ds = new DataSet();
        if (getRid == null) getRid = "1";
        ds = db.GetDataSet("select * from mr_v_resource where rid='" + getRid + "'");
        Image1.ImageUrl = ResolveUrl(ds.Tables[0].Rows[0]["logo"].ToString());
        LabelName.Text = "资源名：" + ds.Tables[0].Rows[0]["rname"].ToString();
        LabelCourse.Text = "所属课程：" + ds.Tables[0].Rows[0]["cname"].ToString();
        LabelOwner.Text = "拥有者：" + ds.Tables[0].Rows[0]["mname"].ToString();
        LabelScore.Text = "难度评分：" + ds.Tables[0].Rows[0]["score"].ToString();
        
        LabelUptime.Text = "上传时间：" + ((DateTime)ds.Tables[0].Rows[0]["upload_time"]).ToLongDateString();
        LabIntro.Text = "简介：" + ds.Tables[0].Rows[0]["introduction"].ToString();
        LabKeyword.Text = "关键词：" + ds.Tables[0].Rows[0]["keyword"].ToString();

        SetTop(0);
        String sid = Session["mid"].ToString();
        ds = db.GetDataSet("select * from mr_v_comment where time > (select last_comment_time from mr_member where mid ='" + sid + "')");
        HyperLinkRecentComment.Text = "最新评论(" + ds.Tables[0].Rows.Count.ToString() + ")";
        HyperLinkRecentComment.NavigateUrl = "~/recentcomment.aspx";
        HyperLinkRecentComment.ForeColor = Color.Blue;
        ds = db.GetDataSet("select * from mr_v_download where time > (select last_download_time from mr_member where mid ='" + sid + "')");
        HyperLinkRecentDownload.Text = "最新下载(" + ds.Tables[0].Rows.Count.ToString() + ")";
        HyperLinkRecentDownload.NavigateUrl = "~/recentdownload.aspx";
        HyperLinkRecentDownload.ForeColor = Color.Blue;
    }
    public void SetTop(int tag)
    {
        DBaccess db = new DBaccess();
        DataSet ds = new DataSet();
        String tablename = "mr_test";
        String condition = "";
        DateTime currentTime = new DateTime();
        currentTime = DateTime.Now;
        if (tag == 0)
        {
            tablename = "mr_v_downloadcount";
            LabelTitle.Text = "总排行榜";
        }
        else if (tag == 1)
        {
            tablename = "mr_v_downloadcount_month ";
            condition = "where year = '" + currentTime.Year.ToString() + "' and month = '" + (currentTime.Month - 1).ToString() + "'";
            LabelTitle.Text = "月排行榜";
        }
        else if (tag == 2)
        {
            tablename = "mr_v_downloadcount_year ";
            condition = "where year = '" + currentTime.Year.ToString() + "'";
            LabelTitle.Text = "年排行榜";
        }
        ds = db.GetDataSet("select top 5 * from " + tablename + condition + "  order by num desc");
        HyperLinkRank1.Text = ds.Tables[0].Rows[0]["rname"].ToString();
        HyperLinkRank1.NavigateUrl = "~/comment.aspx?rid=" + ds.Tables[0].Rows[0]["rid"].ToString();
        LabelCount1.Text = ds.Tables[0].Rows[0]["num"].ToString();
        HyperLinkRank2.Text = ds.Tables[0].Rows[1]["rname"].ToString();
        HyperLinkRank2.NavigateUrl = "~/comment.aspx?rid=" + ds.Tables[0].Rows[0]["rid"].ToString();
        LabelCount2.Text = ds.Tables[0].Rows[1]["num"].ToString();
        HyperLinkRank3.Text = ds.Tables[0].Rows[2]["rname"].ToString();
        HyperLinkRank3.NavigateUrl = "~/comment.aspx?rid=" + ds.Tables[0].Rows[0]["rid"].ToString();
        LabelCount3.Text = ds.Tables[0].Rows[2]["num"].ToString();
        HyperLinkRank4.Text = ds.Tables[0].Rows[3]["rname"].ToString();
        HyperLinkRank4.NavigateUrl = "~/comment.aspx?rid=" + ds.Tables[0].Rows[0]["rid"].ToString();
        LabelCount4.Text = ds.Tables[0].Rows[3]["num"].ToString();
        HyperLinkRank5.Text = ds.Tables[0].Rows[4]["rname"].ToString();
        HyperLinkRank5.NavigateUrl = "~/comment.aspx?rid=" + ds.Tables[0].Rows[0]["rid"].ToString();
        LabelCount5.Text = ds.Tables[0].Rows[4]["num"].ToString();
    }
    protected void ButtonMonth_Click(object sender, EventArgs e)
    {
        SetTop(1);
    }
    protected void ButtonYear_Click(object sender, EventArgs e)
    {
        SetTop(2);
    }
    protected void ButtonAll_Click1(object sender, EventArgs e)
    {
        SetTop(0);
    }
    
    protected void Button2_Click(object sender, EventArgs e)
    {
        Session["search"] = TextBox1.Text;
        Response.Redirect("./test.aspx");
    }
    
}